home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / BSCTRLC.C < prev    next >
C/C++ Source or Header  |  1993-09-10  |  4KB  |  129 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    bsctrlc.c
  5. //   Title:    Base library
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //
  24. //    This module contains code to disable Ctrl-C, Ctrl-Break and Ctrl-Alt-Del.
  25. //
  26. //    The code in this module should be written entirely in C. 
  27. //    Do not use any C++ constructs.
  28. //
  29. //    This module is portable to:
  30. //        DOS 3.X+
  31. //        MS Windows 3.X+
  32. //        OS/2 2.X+
  33. //        OS/2 2.0 PM
  34. //        SCO UNIX.
  35. //
  36. //    The following compilers are supported:
  37. //        MSC 6.0A
  38. //        MSC/C++ 7.0
  39. //        Borland C++ 3.1 for DOS
  40. //        Borland C++ 1.0 for OS/2 2.X
  41. //        SCO UNIX cc
  42. //
  43. //----------------------------------------------------------------------------
  44. #include <bs.h>
  45. #if OS_DOS && COMPILER_BORLAND
  46.  
  47.  
  48. //----------------------------------------------------------------------------
  49. //    Globals
  50. //----------------------------------------------------------------------------
  51. static PBYTE pbModifiers = MK_FP(0,0x417);
  52. static void _interrupt (*oldint9)(void);
  53.  
  54. #define CTRLALT      (0x08|0x04)
  55. #define CTRL            (0x08)
  56. #define DELSCAN      (0x53)
  57. #define CSCAN          (0x46)
  58. #define BREAKSCAN    (0x70)
  59. #define KEYPORT      (0x60)        
  60.  
  61.  
  62. //----------------------------------------------------------------------------
  63. //   Description:    New interrupt handler for INT 9 (keboard monitor)
  64. //    Parameters:
  65. //       Returns:    
  66. //----------------------------------------------------------------------------
  67. void _interrupt new_int_9(void)
  68. {
  69.    if (((((*pbModifiers) & CTRL) == CTRL)
  70.     &&    ((inportb(KEYPORT) == BREAKSCAN) || (inportb(KEYPORT) == CSCAN)))
  71.     || ((((*pbModifiers) & CTRLALT) == CTRLALT) && (inportb(KEYPORT) == DELSCAN)))
  72.         {
  73.         _asm {                                    // Reenable keyboard
  74.             IN   AL,61h                            // Read key
  75.             MOV  AH,AL
  76.             OR   AL,80h
  77.             OUT  61h,AL
  78.             XCHG AL,AH
  79.             OUT  61h,AL
  80.             CLI
  81.             MOV  AL,20h
  82.             OUT  20h,AL
  83.             STI
  84.             }
  85.         }
  86.    else                                            // If the key is not CTRL-C or 
  87.        (*oldint9)();                            // CTRL-BREAK, call the old INT 9 handler
  88. }
  89.  
  90.  
  91. //----------------------------------------------------------------------------
  92. //   Description:    Initialize keyboard monitor. Prevent Ctrl-C, Ctrl-Break and
  93. //                          Ctrl-Alt-Del from breaking out of the program.
  94. //    Parameters:
  95. //       Returns:    
  96. //----------------------------------------------------------------------------
  97. VOID FN_E CtrlCInitialize(void)
  98. {
  99.     if (oldint9 == NULL)
  100.         {
  101.        oldint9 = _dos_getvect(9);  
  102.         _dos_setvect(9,new_int_9);
  103.  
  104.         BaseExitFunc((PFNEXIT)CtrlCTerminate, SYS_EXIT_PRIORITY);
  105.         }
  106.     return ;
  107. }
  108.  
  109.  
  110. //----------------------------------------------------------------------------
  111. //   Description:    Reset keyboard monitors
  112. //    Parameters:
  113. //       Returns:
  114. //----------------------------------------------------------------------------
  115. VOID FN_E CtrlCTerminate(void)
  116. {
  117.     if (oldint9)
  118.         {
  119.        Assert(oldint9 == _dos_getvect(9));
  120.         _dos_setvect(9,oldint9);
  121.         oldint9 = NULL;
  122.         }
  123.     return ;
  124. }
  125. //----------------------------------------------------------------------------
  126. //------------------------------- End of File --------------------------------
  127. //----------------------------------------------------------------------------
  128. #endif
  129.